<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全局组件</title>

</head>
<body>
<div id="yun9">
    <haha></haha>
</div>

<div id="app">
    <haha></haha>
</div>
<!--vue中的监控只能监控声明的属性-->
<script src="../node_modules/vue/dist/vue.js"></script>
<script>

    Vue.component("haha", {
        template: `
       <div>
            <button @click="ageAdd">我是haha组件内部的按钮，我的名字是:{{name}},我的年龄：{{age}}</button>
        </div>
       `,
        data() {
           return{
            name: "张学友",
            age: 50
           }
        },
        methods: {
            ageAdd() {
                this.age++;
            }
        },
        watch:{
           age(newVal,oldVal){
               alert("age发生改变了，新的值为:"+newVal+" 旧的值为："+oldVal);
           }
        }
    })

    let yun9 = new Vue({
        el: "#yun9"
    });

    let app = new Vue({
        el:"#app"
    })
</script>
</body>
</html>